import 'package:flutter/material.dart';

import '../pages/tabs/BottomTabs.dart';
import '../pages/Search.dart';
import '../pages/ProductList.dart';
import '../pages/productContent/ProductContent.dart';
import '../pages/tabs/Cart.dart';
import '../pages/Login.dart';
import '../pages/register/RegisterFirst.dart';
import '../pages/register/RegisterSecond.dart';
import '../pages/register/RegisterThird.dart';
import '../pages/CheckOut.dart';
import '../pages/address/AddressList.dart';
import '../pages/address/AddressAdd.dart';
import '../pages/address/AddressEdit.dart';
import '../pages/Pay.dart';
import '../pages/Order.dart';
import '../pages/OrderDetail.dart';

// 配置路由
final routes = {
  '/': (context,{arguments}) => BottomTabs(),
  '/search': (context,{arguments}) => SearchPage(),
  '/cart': (context,{arguments}) => CartPage(),
  '/productList': (context,{arguments}) => ProductListPage(arguments : arguments),
  '/ProductContent': (context,{arguments}) => ProductContentPage(arguments : arguments),
  '/login': (context,{arguments}) => LoginPage(),
  '/registerFirst': (context, {arguments}) => RegisterFirstPage(),
  '/registerSecond': (context, {arguments}) => RegisterSecondPage(arguments: arguments),
  '/registerThird': (context, {arguments}) => RegisterThirdPage(arguments: arguments),
  '/checkOut': (context, {arguments}) => CheckOutPage(),
  '/addressList': (context, {arguments}) => AddressListPage(),
  '/addressAdd': (context, {arguments}) => AddressAddPage(),
  '/addressEdit': (context, {arguments}) => AddressEditPage(arguments: arguments),
  '/pay': (context, {arguments}) => PayPage(),
  '/order': (context, {arguments}) => OrderPage(),
  '/orderDetail': (context, {arguments}) => OrderDetailPage(arguments: arguments),
};

// 固定写法
Function onGenerateRoute = (RouteSettings settings){
    // 统一处理
    final String name = settings.name;
    final Function pageContentBuilder = routes[name];
    if (pageContentBuilder != null) {
        if (settings.arguments != null) {
          final Route route = MaterialPageRoute(
              builder: (context) =>
                  pageContentBuilder(context, arguments: settings.arguments)
          );
          return route;
        } else {
          final Route route = MaterialPageRoute(
              builder: (context) => pageContentBuilder(context)
          );
          return route;
        }
      }
};